package org.example.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JSONUtil {
    static ObjectMapper objectMapper = new ObjectMapper();
    /** 对象转成json字符串 */
    public  static String obj2str(Object obj) throws JsonProcessingException {
        return objectMapper.writeValueAsString(obj);
    }


    /** JSON字符串转换成对象 */

    public static Object str2obj(String json) throws JsonProcessingException {
        return objectMapper.readValue(json,Object.class);
    }
}
